<template>
  <div class="newslist">
    <el-table :data="tableData" :border="true" stripe style="width: 100%;">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column prop="upload_time" label="日期" width="160"></el-table-column>
      <el-table-column prop="title" label="标题" width="180"></el-table-column>
      <el-table-column prop="types" label="文章类型" width="60"></el-table-column>
      <el-table-column prop="content" label="内容" :show-overflow-tooltip="true" width="500"></el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
            <img :src="scope.row.icon" alt="" width="100" height="100">
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="showEdit(scope.row._id)">编辑</el-button>
            <el-button type="danger" size="mini" @click="removeById(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

import {DelNewslist,GetNewslist, GetNewsListById} from '@/api/index'
import FormatTime from '@/utils/FormatTime'
import { mapMutations } from 'vuex'
export default {
    data() {
        return {
            tableData:[]
        }
    },
    methods:{
        ...mapMutations(['getNewsNum']),
        // 创建添加信息
        async getnewslist(){
            const {data:res}=await GetNewslist()
            console.log(res)
            // res.upload_time=FormatTime(res.upload_time)
            this.getNewsNum(res.length)
            res.forEach(item => {
                item.upload_time=FormatTime(item.upload_time)
                
            });
            this.tableData=res
        },
        // 展示查询信息
        // async showEdit(id){
        //     console.log(id)
        //     const {data:res}=await GetNewslists(id)
        //     console.log(res)
        // },
        async showEdit(id){
            console.log(id)
            const {data:res}=await GetNewsListById(id)
            console.log(res)
            this.$router.push('/deliver/'+id)
        },
        // 删除信息
        // async removeById(id){
        //     console.log(id)
        //     const {data:res}=await DelNewslist(id)
        //     console.log(res)
        //     this.getnewslist()

        // }
        async removeById(id){
            console.log(id)
            const {data:res}=await DelNewslist(id)
            console.log(res)
            this.getnewslist()

        }
        
    },
    created(){
        this.getnewslist()
    }
}
</script>

<style lang="less" scoped>

</style>

